import { h } from 'vue';
import { Modal } from 'ant-design-vue';
import { WarningFilled } from '@ant-design/icons-vue';
import CreateGlasssixCrypto from 'glasssix-crypto-js';

/**
 *
 * @返回 类型: Function - 打开删除弹窗的函数
 */

type TsModalInfo = {
	title?: string;
	okText?: string;
	cancelText?: string;
	contentText?: string;
	centered?: boolean;
};

type TsUseDeleteModal = {
	setOpenDeleteModal: (deleteFun: () => void, modalInfo?: TsModalInfo, expandCallBack?: any) => void;
};

export const useDeleteModal = (): TsUseDeleteModal => {
	/**
	 *
	 * @param contentText 删除弹窗的描述文字信息
	 * @param deleteFun 确认按钮的函数
	 */
	const setOpenDeleteModal = (
		deleteFun: () => void,
		modalInfo: TsModalInfo = { title: '确认删除?', okText: '确定', cancelText: '取消', contentText: '', centered: true },
		expandCallBack?: any
	): void => {
		Modal.confirm({
			class: 'global-delete-modal',
			width: 416,
			icon: h(WarningFilled),
			title: modalInfo.title,
			okText: modalInfo.okText,
			centered: true,
			cancelText: modalInfo.cancelText,
			content: modalInfo.contentText,
			onCancel: () => {
				Modal.destroyAll();
				expandCallBack && expandCallBack();
			},
			onOk: () => deleteFun()
		});
	};

	return {
		setOpenDeleteModal
	};
};
// 国标SM4-CBC加解密
export const useG6Crypto = (): any => {
	const cryptoObj = reactive<{ enCryptoFun?: (value: string) => void; deCryptoFun?: (value: string) => void }>({});

	const cipherName = 'sm4-cbc'; // 对称加密算法名称：如 aes-128-cbc, aes-256-cbc 等
	const symmKey = 'glasssixglasssix'; // 对称加密的密钥，长度符合对应算法要求
	const iv = '0000000000000000'; // 对称加密的初始化向量（或叫偏移量）

	// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
	const GetCryptoFun = async () => {
		const res: Record<string, any> = await CreateGlasssixCrypto(cipherName, symmKey, iv);

		if (res) {
			cryptoObj.enCryptoFun = res.enCryptoFn;
			cryptoObj.deCryptoFun = res.deCryptoFn;
			return res;
		}
	};
	GetCryptoFun();

	return { cryptoObj, GetCryptoFun };
};
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const confirm = (props: any) => {
	return Modal.confirm({
		icon: h(WarningFilled),
		...props
	});
};
